package com.example.my.shop.mybatis.controller;

import com.example.my.shop.mybatis.TbUser;
import com.example.my.shop.mybatis.service.Imp.TbUserServiceImpl;
import com.example.my.shop.mybatis.service.TbUserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(value = "/getUserById")
public class GetUserById extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        TbUserService tbUserService = new TbUserServiceImpl();
        int id = Integer.parseInt(req.getParameter("id"));
        TbUser user = tbUserService.selectUserById(id);
        req.setAttribute("user", user);
        req.getRequestDispatcher("/user_form.jsp").forward(req, resp);
    }
}
